/**
 *  Copyright (C) 2008-2013  Telosys project org. ( http://www.telosys.org/ )
 *
 *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *          http://www.gnu.org/licenses/lgpl.html
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.telosys.common.dataset;

import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * Iterator implementation designed to iterate on a DataSet (row by row)
 * 
 * @author Laurent GUERIN
 *  
 */
public class DataSetIterator implements Iterator<DataRow>
{
    private DataSet _dataset          = null;

    private int     _iCurrentRow = 0;

    /**
     * Constructs an Iterator for the given DataSet
     * 
     * @param dataset
     */
    public DataSetIterator(DataSet dataset)
    {
        _dataset = dataset ;
        _iCurrentRow = 0; // before the first row
    }

    /* (non-Javadoc)
     * @see java.util.Iterator#hasNext()
     */
    public boolean hasNext()
    {
        if ( _iCurrentRow < _dataset.getRowCount() )
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    /* (non-Javadoc)
     * @see java.util.Iterator#next()
     */
//    public Object next()
    public DataRow next()
    {
        if ( _iCurrentRow < _dataset.getRowCount() )
        {
            _iCurrentRow++ ;
            return _dataset.getDataRow(_iCurrentRow) ;            
        }
        else
        {
            throw new NoSuchElementException("No such DataRow in the DataSet");
        }
    }

    /* (non-Javadoc)
     * @see java.util.Iterator#remove()
     */
    public void remove()
    {
        throw new UnsupportedOperationException("No remove operation for DataSet object");
    }
}